﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using BanditGame2.WCFService;

namespace BanditGame2
{
    public partial class ScoreWindow : ChildWindow
    {
        public ScoreWindow()
        {
            InitializeComponent();
            WCFService.WCFServiceClient WCFClient = new WCFService.WCFServiceClient();
            WCFClient.getScoreAllCompleted += new EventHandler<getScoreAllCompletedEventArgs>(GetScoreAllCompleted);
            WCFClient.getScoreAllAsync();
        }

        private void GetScoreAllCompleted(object sender, getScoreAllCompletedEventArgs e)
        {
            dataGrid1.ItemsSource = e.Result;
        }


        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void datePicker1_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            if (datePicker2.SelectedDate == null)
            {
                WCFService.WCFServiceClient WCFClient = new WCFService.WCFServiceClient();
                WCFClient.getScoreDateCompleted += new EventHandler<getScoreDateCompletedEventArgs>(GetScoreDateCompleted);
                if (datePicker1.SelectedDate != null)
                    WCFClient.getScoreDateAsync((DateTime) datePicker1.SelectedDate, DateTime.Now);
            }
            else
            {
                WCFService.WCFServiceClient WCFClient = new WCFService.WCFServiceClient();
                WCFClient.getScoreDateCompleted += new EventHandler<getScoreDateCompletedEventArgs>(GetScoreDateCompleted);
                if (datePicker1.SelectedDate != null)
                    WCFClient.getScoreDateAsync((DateTime)datePicker1.SelectedDate, (DateTime) datePicker2.SelectedDate);
            }
        }

        private void GetScoreDateCompleted(object sender, getScoreDateCompletedEventArgs e)
        {
            dataGrid1.ItemsSource = e.Result;
        }

        private void datePicker2_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            if (datePicker1.SelectedDate == null)
            {
                WCFService.WCFServiceClient WCFClient = new WCFService.WCFServiceClient();
                WCFClient.getScoreDateCompleted += new EventHandler<getScoreDateCompletedEventArgs>(GetScoreDateCompleted);
                if (datePicker2.SelectedDate != null)
                    WCFClient.getScoreDateAsync(new DateTime(1990, 01, 01, 01, 01, 01), (DateTime)datePicker2.SelectedDate);
            }
            else
            {
                WCFService.WCFServiceClient WCFClient = new WCFService.WCFServiceClient();
                WCFClient.getScoreDateCompleted += new EventHandler<getScoreDateCompletedEventArgs>(GetScoreDateCompleted);
                if (datePicker2.SelectedDate != null)
                    WCFClient.getScoreDateAsync((DateTime)datePicker1.SelectedDate, (DateTime)datePicker2.SelectedDate);
            }
        }
    }
}

